package io.xiyou.order.listener;

import com.alibaba.fastjson.JSON;
import io.xiyou.order.api.IOrderService;
import io.xiyou.order.api.bo.AddOrderBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName：QueueConsumerListener
 * @Author：西柚
 * @Date：2021/10/28 6:07 下午
 * @Versiion：1.0
 */
@Slf4j
@Component
public class QueueConsumerListener {

    @Autowired
    private IOrderService orderService;

    //queue模式的消费者
    @JmsListener(destination = "${spring.activemq.queue-name}", containerFactory = "queueListener")
    public void readActiveQueue(String message) {
        log.info("queue接收到：" + message);

        AddOrderBO addOrderBO = JSON.parseObject(message, AddOrderBO.class);

        orderService.createOrder(addOrderBO);
    }

}
